<template>
  <div class="home">
    <Card>
       <p slot="title">基本信息</p>
       <Row>
         <i-col :xs="8" class="col" v-for="(infor, i) in basicData" :key="`infor-${i}`">
          <basic-news :infor="infor"></basic-news>
         </i-col>
       </Row>
    </Card>
    <div style="height: 10px;"></div>
    <Card class="twocard">
      <p slot="title">今/昨日订单</p>
      <Row :gutter="20">
         <i-col :xs="4" class="col"  v-for="(infor, i) in orderList" :key="`infor-${i}`" >
             <basic-news :infor="infor"></basic-news>
         </i-col>
       </Row>
    </Card>
  </div>
</template>
<script>
import InforCard from '_c/info-card'
import CountTo from '_c/count-to'
import { ChartPie, ChartBar } from '_c/charts'
import Example from './example.vue'
import BasicNews from '@/components/basic-news/basic-news.vue'
import { home } from '@/api/user'
export default {
  name: 'home',
  components: {
    BasicNews,
    InforCard,
    ChartPie,
    CountTo,
    ChartBar,
    Example
  },
  data () {
    return {
      userInfo: {},
      orderData: {},
      basicData: [
        { title: '账户余额', count: '', unit: '元' },
        { title: '代付余额', count: '', unit: '元' },
        { title: '冻结金额', count: '', unit: '元' },
        { title: '保证金', count: '', unit: '元' },
        { title: '代付订单总数', count: '0', unit: '个' },
        { title: '代付总额', count: '0', unit: '元' }
      ],
      orderList: [

        { title: '今日代付订单', count: '0', unit: '个' },
        { title: '今日代付总额', count: '0', unit: '元' },
        { title: '今日代付手续费总额', count: 10000, unit: '元' },
        { title: '昨日代付订单', count: '0', unit: '个' },
        { title: '昨日代付总额', count: '20', unit: '元' },
        { title: '昨日代付手续费总额', count: 100, unit: '元' }

      ]
    }
  },

  mounted () {
    this.userInfo = this.$store.state.user.userInfo
    this.basicData[0].count = this.userInfo.now_money
    this.basicData[1].count = this.userInfo.paid_money
    this.basicData[2].count = this.userInfo.frozen_money
    this.basicData[3].count = this.userInfo.earnest_money
  },
  methods: {
    getHome () {
      let uid = this.$store.state.user.userInfo.uid
      home(uid)
        .then(res => {
          this.orderData = res.data
          this.basicData[4].count = this.orderData.totalPaidOrder
          this.basicData[5].count = this.orderData.sumAmount
          this.orderList[0].count = this.orderData.todayPaidOrder
          this.orderList[1].count = this.orderData.todayAmount
          this.orderList[2].count = this.orderData.todayPoundage
          this.orderList[3].count = this.orderData.yesterdayPaidOrder
          this.orderList[4].count = this.orderData.yesterdayAmount
          this.orderList[5].count = this.orderData.yesterdayPoundage
        }).catch(err => {
          this.$message.error(err.msg)
        })
    }
  },
  created () {
    this.getHome()
  }
}
</script>

<style lang="less">
 @import './home.less';
.count-style{
  font-size: 30px;
}
</style>
